package com.four.user.controller;

import com.four.user.entity.User;
import com.four.user.service.UserService;
import com.guli.common.utils.R;
import com.guli.common.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:wsy
 * @Date: 2021/12/16/13:32
 * @Description
 */
@RestController
@RequestMapping("user/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     * @param userPhone
     * @param code
     * @return
     */
    @PostMapping("/login/{userPhone}")
    public R login(@PathVariable("userPhone")String userPhone, String code){
        return userService.login(userPhone,code);
    }

    /**
     * 发送验证码
     * @param userPhone
     * @return
     */
    @PostMapping("/sendMsg/{userPhone}")
    public R sendMsg(@PathVariable("userPhone") String userPhone){
        return userService.sendMsg(userPhone);
    }

    /**
     * 根据登录人名查询
     * @param loginName
     * @return
     */
    @GetMapping("/findByUname/{loginName}")
    public User findByUname(@PathVariable("loginName")String loginName){
        User user=userService.findByUname(loginName);
        return user;
    }

    /**
     * 根据用户编号查询
     * @param userId
     * @return
     */
    @GetMapping("/getUserById/{userId}")
    public UserVo getUserById(@PathVariable("userId")Integer userId) {

        return userService.getUserById(userId);
    }
}
